package cn.cupster.motionlayoutshare

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import cn.cupster.motionlayoutshare.example.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //1.收藏/点赞动画
        addClickEvent(R.id.btnCollection) {
            launchPage(CollectionActivity::class.java)
        }
        //2.公告轮播
        addClickEvent(R.id.btnPublicNotice) {
            launchPage(PublicNoticeActivity::class.java)
        }
        //3.跑马灯
        addClickEvent(R.id.btnMarquee) {
            launchPage(MarqueeActivity::class.java)
        }
        //4.弹幕
        addClickEvent(R.id.btnDanmaku) {
            launchPage(DanmakuActivity::class.java)
        }
        //5.礼物
        addClickEvent(R.id.btnGift) {
            launchPage(SendGiftActivity::class.java)
        }
        //5.头像轮播
        addClickEvent(R.id.btnAvatarPlay) {
            launchPage(AvatarMarqueActivity::class.java)
        }
    }

    private fun addClickEvent(viewId: Int, block: (obj: Any?) -> Unit) {
        val view = findViewById<View>(viewId)
        view.setOnClickListener {
            block(it.tag)
        }
    }

    private fun <T : Activity> launchPage(clazz: Class<T>) {
        val target = Intent(this, clazz)
        startActivity(target)
    }

}